news and examples/README.md

Documentation

Find current issues and a to do in this README. See current changes in the NEWS file. Even though this package is primarily designed to match the needs of EEG data analysis, all my examples use the not-so-EEG chick weight data set, because that's easier to reproduce. But hey. Brain waves. Chick weights. What's the difference, really?

File Administration

delete_empty_BA_files()

Meant to delete empty or pseudo-empty export files exported from the Brain Vision Analyzer, but can in principle be used for any .txt, .dat or .csv files that (are supposed to) contain data tables. Will go through a given folder and delete files that are empty/blank or contain nothing but a header. See possible specifications - and the function in full action - in the example folder, where dummy files are provided as well.

read_out_ID()

Read out participant IDs of a specified format from filenames. Alternatively, it can give back the filenames that start with valid IDs in a given folder. See examples in the example folder.

Plotting Functions

shade_components()

Generate a dataframe and the lines of code to add to ggplot() in order to shade the areas of your plot representing components. The main output of the function is a dataframe that contains all the information needed to shade the areas of your EEG components. Simultaneously, shade_components() will print the code you need to add to your plot to insert your newly created component shading. Note that you need to replace 'YOURDF' with the name of the object you saved the function's output to. Make sure you add geom_rect() before your other geoms so the shading lies below the data you're plotting. Don't forget to add + before and/or after the additional lines if needed. Also note that a specific order of geoms in your plot may be required, as well as certain requirements how to pass your data to ggplot(). See examples for clarification.

# Plot before
ggplot() +
  geom_line(data = av_chicks, aes(x = Time, y = weight, colour = Diet)) +
  chick_theme

# Throw some shade
library(ForBioPsy)
shading <- shade_components(components = c("phase 1", "phase 2", "phase 3"),
                            durations = c("5 - 10", "10.5 - 12", "16 - 19"))
# Plot afterwards
ggplot() +
  geom_rect(data = shading,
            aes(xmin = xstart, xmax = xend, ymin = -Inf, ymax = Inf,
                fill = component), alpha = .5) +
  scale_fill_manual('component', values = c('#E3E3E3', '#C8C6C6', '#E3E3E3')) +
  geom_line(data = av_chicks, aes(x = Time, y = weight, colour = Diet)) +
  chick_theme

generate_shifted_axis()

Generate a dataframe and geoms to add an auxiliary axis to a plot. The main output of the function is a dataframe that contains all the information needed to build an auxiliary axis with tick marks for your plot which cross the orthogonal axis at a specified intercept. Simultaneously, generate_shifted_axis() will print the code you need to add to your plot to insert your newly created auxiliary axis. Note that you need to replace 'YOURDF' with the name of the object you saved the function's output to. Head to examples to see it in full action, but have a little taste here:

# Plot before
ggplot() +
  geom_line(data = av_chicks, aes(x = Time, y = weight, colour = Diet)) +
  chick_theme

# Generate an auxiliary x-axis
x_ticks <- generate_shifted_axis(
  limits = c(0, 20), steps = 5, other_ax_steps = 50,
  axis = "x", intercept = 150
)
# Will print
# x-axis generated.
#
# Please add the following geoms to your plot and replace 'YOURDF' with the
# object you saved this function's output in:
#
# geom_hline(yintercept = 150) +
# geom_segment(data = 'YOURDF', aes(x = ticks, y = intercept - tick_sz * .5,
# xend = ticks, yend = intercept + tick_sz * .5))
# Add it to the plot
ggplot() +
  geom_line(data = av_chicks, aes(x = Time, y = weight, colour = Diet)) +
  chick_theme +
  geom_hline(yintercept = 150) +
  geom_segment(data = x_ticks,
               aes(x = ticks, y = intercept - tick_sz * .5,
                   xend = ticks, yend = intercept + tick_sz * .5))



einGlasRotwein/ForBioPsy documentation built on Nov. 4, 2019, 11:49 a.m.